//
//  CinemaViewController.m
//  UI 作业 - 豆瓣电影
//
//  Created by hesiyao on 15/12/22.
//  Copyright © 2015年 www.lanou3g.com蓝鸥科技. All rights reserved.
//

#import "CinemaViewController.h"
#import "CinemaModel.h"
#import "CinemaCell.h"
#import "CinemaDetailViewController.h"
@interface CinemaViewController () <UITableViewDataSource, UITableViewDelegate>
@property (nonatomic, retain) UITableView *tableview;
@property (nonatomic, retain) NSMutableArray *arr;
@end

@implementation CinemaViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor whiteColor];
    
    self.tableview = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStylePlain];
    [self.view addSubview:_tableview];
    _tableview.dataSource = self;
    _tableview.delegate = self;
    _tableview.contentInset = UIEdgeInsetsMake(0, 0, 49, 0);
    
    [_tableview registerClass:[CinemaCell class] forCellReuseIdentifier:@"cell"];
    
    self.navigationItem.title = @"影院";
    [self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"bg_nav@2x"] forBarMetrics:UIBarMetricsDefault];
    [self DataHander];
    
}

-(void)DataHander
{
    NSString *path = [[NSBundle mainBundle] pathForResource:@"cinema" ofType:@"plist"];
    NSArray *arr = [NSArray arrayWithContentsOfFile:path];
    self.arr = [CinemaModel modelHandlerCreate:arr];
    
    
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return _arr.count;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    CinemaCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
    CinemaModel *m = _arr[indexPath.row];
    cell.titleLabel.text = m.cinemaName;
    cell.addressLabel.text = m.address;
    cell.phoneLabel.text = m.telephone;
    cell.img.image = [UIImage imageNamed:@"bg_eventlistcell@2x"];
    return cell;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    CinemaModel *m = _arr[indexPath.row];
    CGFloat h = [CinemaCell heightWithTitle:m.cinemaName];
    CGFloat h1 = [CinemaCell heightWithAddress:m.address];
    CGFloat h2 = [CinemaCell heightWithPhone:m.telephone];
    return h + h1 + h2 + 150;
}

/// 点击cell进入详情页面
//- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
//{
//    CinemaDetailViewController *detailVC = [[CinemaDetailViewController alloc] init];
//    [self.navigationController pushViewController:detailVC animated:YES];
//}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
